<?php
class A {
    public static function say(){
        return get_called_class();
    }
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        //self::who();
        static::who();
    }
}

class B extends A {
    public static function who() {
        echo __CLASS__;
    }
}

/*
//B::test();
//echo B::say();

list($a,$b,$c) = array('a','b','C');
//explode('_','a_b');

echo $a,$b,$c;
exit;


$people = array("Peter", "Joe", "Glenn", "Cleveland",0,false,100);
reset($people);

while(list($k)=each($people)){
    echo $people[$k].'<br />';
}
reset($people);
while (list($key, $val) = each($people))
{
    echo "$key => $val<br />";
}

while(list($k)=each($people));

*/

abstract class Singleton {

    public static $aoInstance = array();
    protected function __construct() {

    }

    final public static function getInstance() {
        //static $aoInstance = array();
        $calledClassName = get_called_class();
        if (! isset (self::$aoInstance[$calledClassName])) {
            self::$aoInstance[$calledClassName] = new $calledClassName();
        }

        return self::$aoInstance[$calledClassName];
    }

    final private function __clone() {
    }
}

class DatabaseConnection extends Singleton {

    protected $connection;

    protected function __construct() {
        // @todo Connect to the database
        echo 'DatabaseConnection<br />';
    }

    public function __destruct() {
        // @todo Drop the connection to the database
    }
}

//$oDbConn = new DatabaseConnection();  // Fatal error


class DatabaseConnection2 extends Singleton {

    protected $connection;

    protected function __construct() {
        // @todo Connect to the database
        echo 'DatabaseConnection2<br />';
    }

    public function __destruct() {
        // @todo Drop the connection to the database
    }
}

class DatabaseConnection3 extends Singleton {

    protected $connection;

    protected function __construct() {
        // @todo Connect to the database
        echo 'DatabaseConnection3<br />';
    }

    public function __destruct() {
        // @todo Drop the connection to the database
    }
}

class DatabaseConnection4 extends Singleton {

    protected $connection;

    protected function __construct() {
        // @todo Connect to the database
        echo 'DatabaseConnection4<br />';
    }

    public function __destruct() {
        // @todo Drop the connection to the database
    }
}
$oDbConn = DatabaseConnection::getInstance();  // Returns single instance
$oDbConn = DatabaseConnection2::getInstance();  // Returns single instance
$oDbConn = DatabaseConnection3::getInstance();  // Returns single instance
$oDbConn = DatabaseConnection4::getInstance();  // Returns single instance

$oDbConn = DatabaseConnection::getInstance();  // Returns single instance
$oDbConn = DatabaseConnection2::getInstance();  // Returns single instance
$oDbConn = DatabaseConnection3::getInstance();  // Returns single instance
$oDbConn = DatabaseConnection4::getInstance();  // Returns single instance




abstract class DataRecord {
    private static $db; // MySQLi-Connection, same for all subclasses
    private static $table = array(); // Array of tables for subclasses

    public static function init($classname, $table, $db = false) {
        if (!($db === false)) self::$db = $db;
        self::$table[$classname] = $table;
    }

    public static function getDB() { return self::$db; }
    public static function getTable($classname) { return self::$table[$classname]; }
}

class UserDataRecord extends DataRecord {
    public static function fetchFromDB() {
        $result = parent::getDB()->query('select * from '.parent::getTable('UserDataRecord').';');

        // and so on ...
        return $result; // An array of UserDataRecord objects
    }
}

$db = new MySQLi();
UserDataRecord::init('UserDataRecord', 'users', $db);
$users = UserDataRecord::fetchFromDB();
?>